package com.wsir.controller;

import com.springmvc.annotation.AutoWired;
import com.springmvc.annotation.Controller;
import com.springmvc.annotation.RequestMapping;
import com.springmvc.annotation.RequestParm;
import com.wsir.pojo.User;
import com.wsir.service.UserService;
import com.wsir.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author Lao Wang
 * @Date 2023/11/14
 * @Description
 **/
@Controller //默认就是类名，首字母小写
public class UserController {
    @AutoWired
    UserService userService;
    @RequestMapping("/user/query")
    public void findUsers(HttpServletRequest rq, HttpServletResponse rs,@RequestParm("name") String name){
        //处理响应内容中文乱码问题
        rs.setContentType("text/html;charset=utf-8");
        try {
            List<User> users = userService.findUsers(name);
            PrintWriter out = rs.getWriter();
            out.print("<h1>SpringMvc控制器："+name+"</h1>");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
